package com.config;

import com.bug.VocabularyCatchStrategy;
import com.bug.mamage.WordInfoManage;
import com.model.WordInfo;
import com.model.WordTable;
import com.service.WordInfoService;
import com.service.WordTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class NetBugConfig {

    @Resource
    private WordInfoService wordInfoService;

    @Bean
    public WordInfoManage wordInfoManage() {
        WordInfoManage wordInfoManage = new WordInfoManage(new VocabularyCatchStrategy());

        // 设置回调填充完的数据处理流程
        wordInfoManage.setWordFullCallback(() -> {
            WordInfo wordInfo;
            do{
                wordInfo = wordInfoManage.pollIsDoneWord();
                if(!wordInfoService.hasWord(wordInfo.getWord())) {
                    wordInfoService.saveWord(wordInfo);
                }
            }while (wordInfo == null);
        });

        return wordInfoManage;
    }
}
